<template>
  <v-dialog
    :title="title"
    :close-on-click-modal="false"
    v-model="visible">
    <el-form style="overflow: hidden;overflow-y: scroll;" :model="inputForm" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'" label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="12">
            <el-form-item label="地点" prop="venueName"
                :rules="[
                 ]">
              <el-input v-model="inputForm.venueName" placeholder="请填写时间段"   readonly  ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="日期" prop="myCreateTime"
                :rules="[
                 ]">
                <el-date-picker
                      style="width: 100%;"
                      v-model="inputForm.myCreateTime"
                      type="date"
                      readonly
                      value-format="YYYY-MM-DD"
                      placeholder="选择日期时间">
                    </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="空闲时间段" prop="time"
                :rules="[
                  {
                    required: true,
                    message: '时间段不能为空',
                    trigger: 'blur',
                  },
                 ]">
              <el-select
                v-model="inputForm.time"
                style="width: 200px;"
                placeholder="请选择"
              >
                <el-option
                  v-for="role in selectStatus"
                  :key="role.value"
                  :label="role.label"
                  :value="role.value"
                >
                </el-option>
              </el-select>
           </el-form-item>
        </el-col>
        <el-col >
            <el-form-item label="申请理由" prop="content"
                :rules="[
                  {
                    required: true,
                    message: '申请理由不能为空',
                    trigger: 'blur',
                  },
                 ]">
              <el-input
                v-model="inputForm.content"
                autosize
                type="textarea"
                placeholder="请输入"
              />
           </el-form-item>
        </el-col>
        </el-row>
    </el-form>
    <template #footer>    
        <span class="dialog-footer">
          <el-button @click="visible = false" icon="circle-close">关闭</el-button>
          <el-button  type="primary" v-if="method != 'view'" @click="doSubmit()" icon="circle-check" v-noMoreClick>确定</el-button>
        </span>
    </template>    
  </v-dialog>
</template>

<script>
  import venueStatusService from '@/api/resource/venueStatusService'
  import venueApplyService from '@/api/resource/venuApplyService.js'
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        selectStatus:[],
        inputForm: {
          venueId: '',
          venueName: '',
          time: '',
          userId:'',
          userName:'',
          myCreateTime:'',
          content:''
        }
      }
    },
    components: {
    },
    created () {
    },
    methods: {
      apply(val){
        this.method='edit'
        this.visible = true
        this.loading = false
        this.inputForm.venueId=val.venueId
        this.inputForm.venueName=val.venueName
        this.inputForm.userId=this.$TOOL.data.get("USER_INFO").id
        this.inputForm.userName=this.$TOOL.data.get("USER_INFO").name
        this.inputForm.myCreateTime=val.date
        // this.inputForm=val
        this.selectStatus=[]
        val.am1=='空闲'?this.selectStatus.push({value:"0",label:"8：30-10：05"}) : 1
        val.am2=='空闲'?this.selectStatus.push({value:"1",label:"10：25-12：00"}) : 1
        val.pm1=='空闲'?this.selectStatus.push({value:"2",label:"14：30-16：05"}) : 1
        val.pm2=='空闲'?this.selectStatus.push({value:"3",label:"16：15-17：50"}) : 1
        val.night1=='空闲'?this.selectStatus.push({value:"4",label:"18：30-19：05"}) : 1
        val.night2=='空闲'?this.selectStatus.push({value:"5",label:"19：15-20：50"}) : 1
        console.log(this.selectStatus)
      },
      init (method, id) {
        this.method = method
        this.inputForm.id = id
        if (method === 'add') {
          this.title = `新建查看场地状态`
        } else if (method === 'edit') {
          this.title = '修改查看场地状态'
        } else if (method === 'view') {
          this.title = '查看查看场地状态'
        }
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
            venueStatusService.queryById(this.inputForm.id).then((data) => {
              this.inputForm = this.recover(this.inputForm, data)
              this.loading = false
            })
          }
        })
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            venueApplyService.save(this.inputForm)
            .then((data)=>{
              this.visible = false
              this.$message.success(data)
              this.$emit('refreshDataList')
              this.loading = false
            })
            // venueStatusService.save(this.inputForm).then((data) => {
            //   this.visible = false
            //   this.$message.success(data)
            //   this.$emit('refreshDataList')
            //   this.loading = false
            // }).catch(() => {
            //   this.loading = false
            // })
          }
        })
      }
    }
  }
</script>

  
